; RemoteMaster 安装程序脚本
; 使用 NSIS (Nullsoft Scriptable Install System) 编译

!define APP_NAME "RemoteMaster"
!define APP_VERSION "1.0.0"
!define APP_PUBLISHER "RemoteMaster Team"
!define APP_DIR "RemoteMaster"

; 安装程序基本信息
Name "${APP_NAME} ${APP_VERSION}"
OutFile "${APP_NAME}_${APP_VERSION}_Setup.exe"
InstallDir "$PROGRAMFILES\${APP_DIR}"
InstallDirRegKey HKCU "Software\${APP_NAME}" ""
RequestExecutionLevel admin

; 包含Modern UI
!include "MUI2.nsh"

; 界面设置
!define MUI_ABORTWARNING

; 安装页面
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "..\..\LICENSE"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

; 卸载页面
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

; 语言
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese"

; 安装程序图标
!define MUI_ICON "..\..\resources\icons\application.ico"
!define MUI_UNICON "..\..\resources\icons\application.ico"

Section "RemoteMaster" SecMain
    ; 设置输出路径
    SetOutPath "$INSTDIR"
    
    ; 复制文件
    File "..\..\build_vs2022\Release\RemoteMaster.exe"
    File "..\..\README.md"
    File "..\..\LICENSE"
    
    ; 复制Qt运行库
    File "*.dll"
    File /r "Qt6Core.dll"
    File /r "Qt6Gui.dll"
    File /r "Qt6Network.dll"
    File /r "Qt6OpenGL.dll"
    File /r "Qt6Widgets.dll"
    
    ; 创建开始菜单快捷方式
    CreateDirectory "$SMPROGRAMS\${APP_NAME}"
    CreateShortCut "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk" "$INSTDIR\RemoteMaster.exe"
    CreateShortCut "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk" "$INSTDIR\uninstall.exe"
    
    ; 创建桌面快捷方式
    CreateShortCut "$DESKTOP\${APP_NAME}.lnk" "$INSTDIR\RemoteMaster.exe"
    
    ; 写入注册表
    WriteRegStr HKCU "Software\${APP_NAME}" "" "$INSTDIR"
    WriteUninstaller "$INSTDIR\uninstall.exe"
    ; 注册文件关联 (可选)
    WriteRegStr HKCR ".rmt" "" "${APP_NAME}"
    WriteRegStr HKCR "${APP_NAME}" "" "RemoteMaster Connection"
    WriteRegStr HKCR "${APP_NAME}\DefaultIcon" "" "$INSTDIR\RemoteMaster.exe,0"
    WriteRegStr HKCR "${APP_NAME}\shell\open\command" "" '"$INSTDIR\RemoteMaster.exe" "%1"'
SectionEnd

Section "Uninstall"
    ; 删除文件
    Delete "$INSTDIR\RemoteMaster.exe"
    Delete "$INSTDIR\README.md"
    Delete "$INSTDIR\LICENSE"
    Delete "$INSTDIR\*.dll"
    
    ; 删除目录
    RMDir "$INSTDIR"
    
    ; 删除开始菜单快捷方式
    Delete "$SMPROGRAMS\${APP_NAME}\${APP_NAME}.lnk"
    Delete "$SMPROGRAMS\${APP_NAME}\Uninstall.lnk"
    RMDir "$SMPROGRAMS\${APP_NAME}"
    
    ; 删除桌面快捷方式
    Delete "$DESKTOP\${APP_NAME}.lnk"
    
    ; 删除注册表项
    DeleteRegKey HKCU "Software\${APP_NAME}"
    DeleteRegKey HKCR ".rmt"
    DeleteRegKey HKCR "${APP_NAME}"
SectionEnd